home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / surfdoc3.zip / HIMEM.DOC < prev    next >
Text File  |  1991-09-29  |  34KB  |  781 lines

  1.                        Extended Memory Specification
  2.                        =============================
  3.  
  4.     The purpose of this document is to define the Extended Memory Specifica-
  5. tion (XMS) version 2.00 for MS-DOS.  XMS allows DOS programs to utilize
  6. additional memory found in Intel's 80286 and 80386 based machines in
  7. a consistent, machine independent manner.  With some restrictions, XMS adds
  8. almost 64K to the 640K which DOS programs can access directly.    Depending on
  9. available hardware, XMS may provide even more memory to DOS programs.  XMS
  10. also provides DOS programs with a standard method of storing data in extended
  11. memory.
  12.  
  13. DEFINITIONS:
  14. ------------
  15.  
  16.     Extended
  17.     Memory      -   Memory in 80286 and 80386 based machines which is located
  18.                     above the 1MB address boundary.
  19.  
  20.     High Memory
  21.     Area (HMA)  -   The first 64K of extended memory.  The High Memory
  22.             Area is unique because code can be executed in it while
  23.             in real mode.  The HMA officially starts at FFFF:10h
  24.             and ends at FFFF:FFFFh making it 64K-16 bytes in length.
  25.                     
  26.     Upper Memory
  27.     Blocks (UMBs)-  Blocks of memory available on some 80x86 based machines
  28.                     which are located between DOS's 640K limit and the
  29.                     1MB address boundary.  The number, size, and location
  30.                     of these blocks vary widely depending upon the types
  31.                     of hardware adapter cards installed in the machine.
  32.                     
  33.     Extended Memory
  34.     Blocks (EMBs)-  Blocks of extended memory located above the HMA which
  35.                     can only be used for data storage.
  36.                     
  37.     A20 Line    -   The 21st address line of 80x86 CPUs.  Enabling the A20
  38.                     line allows access to the HMA.
  39.  
  40.     XMM         -   An Extended Memory Manager.  A DOS device driver which
  41.                     implements XMS.  XMMs are machine specific but allow
  42.             programs to use extended memory in a machine-independent
  43.             manner.
  44.     
  45.     HIMEM.SYS   -   The Extended Memory Manager currently being distributed
  46.                     by Microsoft.
  47.  
  48. Helpful Diagram:
  49.  
  50.     |                                                       |   Top of Memory
  51.     |                                                       |
  52.     |                                                       |
  53.     |                        /\                             |
  54.     |                       /||\                            |
  55.     |                        ||                             |
  56.     |                        ||                             |
  57.     |.......................................................|
  58.     |                                                       |
  59.     |                                                       |
  60.     |             Possible Extended Memory Block            |
  61.     |                                                       |
  62.     |                                                       |
  63.     |.......................................................|
  64.     |                        ||                             |
  65.     |                        ||                             |
  66.     |                       \||/                            |
  67.     |                        \/                             |
  68.     |                                                       |
  69.     |                                                       |
  70.     |       Other EMBs could exist above 1088K (1MB+64K)    |
  71.     |                                                       |
  72.     |                                                       |
  73.     |-------------------------------------------------------|   1088K
  74.     |                                                       |
  75.     |                                                       |
  76.     |                The High Memory Area                   |
  77.     |                                                       |
  78.     |                                                       |
  79.     |=======================================================|   1024K or 1MB
  80.     |                                                       |
  81.     |                        /\                             |
  82.     |                       /||\                            |
  83.     |                        ||                             |
  84.     |                        ||                             |
  85.     |.......................................................|
  86.     |                                                       |
  87.     |             Possible Upper Memory Block               |
  88.     |.......................................................|
  89.     |                        ||                             |
  90.     |                        ||                             |
  91.     |                       \||/                            |
  92.     |                        \/                             |
  93.     |                                                       |
  94.     |        Other UMBs could exist between 640K and 1MB    |
  95.     |                                                       |
  96.     |-------------------------------------------------------|   640K
  97.     |                                                       |
  98.     |                                                       |
  99.     |                                                       |
  100.     |             Conventional or DOS Memory                |
  101.     |                                                       |
  102.     |                                                       |
  103.     |                                                       |
  104.     |                                                       |
  105.     |                                                       |
  106.     +-------------------------------------------------------+   0K
  107. DRIVER INSTALLATION:
  108. --------------------
  109.  
  110.     An XMS driver is installed by including a DEVICE= statement in the
  111. machine's CONFIG.SYS file.  It must be installed prior to any other
  112. devices or TSRs which use it.  An optional parameter after the driver's 
  113. name (suggested name "/HMAMIN=") indicates the minimum amount of space in
  114. the HMA a program can use.  Programs which use less than the minimum will
  115. not be placed in the HMA.  See "Prioritizing HMA Usage" below for more
  116. information.  A second optional parameter (suggested name "/NUMHANDLES=")
  117. allows users to specify the maximum number of extended memory blocks which
  118. may be allocated at any time.
  119.  
  120.     NOTE: XMS requires DOS 3.00 or above.
  121.  
  122.  
  123. THE PROGRAMMING API:
  124. --------------------
  125.  
  126.     The XMS API Functions are accessed via the XMS driver's Control Function.
  127. The address of the Control Function is determined via INT 2Fh.  First, a
  128. program should determine if an XMS driver is installed.  Next, it should
  129. retrieve the address of the driver's Control Function.  It can then use any
  130. of the available XMS functions.  The functions are divided into several
  131. groups:
  132.  
  133.         1. Driver Information Functions (0h)
  134.         2. HMA Management Functions (1h-2h)
  135.     3. A20 Management Functions (3h-7h)
  136.         4. Extended Memory Management Functions (8h-Fh)
  137.         5. Upper Memory Management Functions (10h-11h)
  138.  
  139.  
  140. DETERMINING IF AN XMS DRIVER IS INSTALLED:
  141. ------------------------------------------
  142.  
  143.     The recommended way of determining if an XMS driver is installed is to
  144. set AH=43h and AL=00h and then execute INT 2Fh.  If an XMS driver is available,
  145. 80h will be returned in AL.
  146.  
  147.     Example:
  148.             ; Is an XMS driver installed?
  149.             mov     ax,4300h
  150.             int     2Fh         
  151.             cmp     al,80h  
  152.             jne     NoXMSDriver
  153.             
  154.  
  155. CALLING THE API FUNCTIONS:
  156. --------------------------
  157.  
  158.     Programs can execute INT 2Fh with AH=43h and AL=10h to obtain the address
  159. of the driver's control function.  The address is returned in ES:BX.  This
  160. function is called to access all of the XMS functions.  It should be called
  161. with AH set to the number of the API function requested.  The API function
  162. will put a success code of 0001h or 0000h in AX.  If the function succeeded
  163. (AX=0001h), additional information may be passed back in BX and DX.  If the
  164. function failed (AX=0000h), an error code may be returned in BL.  Valid
  165. error codes have their high bit set.  Developers should keep in mind that
  166. some of the XMS API functions may not be implemented by all drivers and will
  167. return failure in all cases.
  168.  
  169.     Example:
  170.             ; Get the address of the driver's control function
  171.             mov     ax,4310h
  172.             int     2Fh
  173.             mov     word ptr [XMSControl],bx        ; XMSControl is a DWORD
  174.             mov     word ptr [XMSControl+2],es
  175.             
  176.             ; Get the XMS driver's version number
  177.             mov     ah,00h
  178.             call    [XMSControl]    ; Get XMS Version Number
  179.  
  180.     NOTE: Programs should make sure that at least 256 bytes of stack space
  181.       is available before calling XMS API functions.
  182.  
  183.  
  184. API FUNCTION DESCRIPTIONS:
  185. --------------------------
  186.  
  187.     The following XMS API functions are available:
  188.  
  189.        0h)  Get XMS Version Number
  190.        1h)  Request High Memory Area
  191.        2h)  Release High Memory Area
  192.        3h)  Global Enable A20
  193.        4h)  Global Disable A20
  194.        5h)  Local Enable A20
  195.        6h)  Local Disable A20
  196.        7h)  Query A20
  197.        8h)  Query Free Extended Memory
  198.        9h)  Allocate Extended Memory Block
  199.        Ah)  Free Extended Memory Block
  200.        Bh)  Move Extended Memory Block
  201.        Ch)  Lock Extended Memory Block
  202.        Dh)  Unlock Extended Memory Block
  203.        Eh)  Get Handle Information
  204.        Fh)  Reallocate Extended Memory Block
  205.       10h)  Request Upper Memory Block
  206.       11h)  Release Upper Memory Block
  207.  
  208. Each is described below.
  209.  
  210.  
  211. Get XMS Version Number (Function 00h):
  212. --------------------------------------
  213.  
  214.     ARGS:   AH = 00h
  215.     RETS:   AX = XMS version number
  216.         BX = Driver internal revision number
  217.         DX = 0001h if the HMA exists, 0000h otherwise
  218.     ERRS:   None
  219.  
  220.     This function returns with AX equal to a 16-bit BCD number representing
  221. the revision of the DOS Extended Memory Specification which the driver
  222. implements (e.g. AX=0235h would mean that the driver implemented XMS version
  223. 2.35).    BX is set equal to the driver's internal revision number mainly for
  224. debugging purposes.  DX indicates the existence of the HMA (not its
  225. availability) and is intended mainly for installation programs.
  226.     
  227.     NOTE: This document defines version 2.00 of the specification.
  228.  
  229.  
  230. Request High Memory Area (Function 01h):
  231. ----------------------------------------
  232.  
  233.     ARGS:   AH = 01h
  234.             If the caller is a TSR or device driver,
  235.                 DX = Space needed in the HMA by the caller in bytes
  236.             If the caller is an application program,
  237.                 DX = FFFFh     
  238.     RETS:   AX = 0001h if the HMA is assigned to the caller, 0000h otherwise
  239.     ERRS:   BL = 80h if the function is not implemented
  240.         BL = 81h if a VDISK device is detected
  241.         BL = 90h if the HMA does not exist
  242.         BL = 91h if the HMA is already in use
  243.         BL = 92h if DX is less than the /HMAMIN= parameter
  244.  
  245.     This function attempts to reserve the 64K-16 byte high memory area for
  246. the caller.  If the HMA is currently unused, the caller's size parameter is
  247. compared to the /HMAMIN= parameter on the driver's command line.  If the
  248. value passed by the caller is greater than or equal to the amount specified
  249. by the driver's parameter, the request succeeds.  This provides the ability
  250. to ensure that programs which use the HMA efficiently have priority over
  251. those which do not.
  252.  
  253.     NOTE: See the sections "Prioritizing HMA Usage" and "High Memory Area
  254.           Restrictions" below for more information.
  255.  
  256.  
  257. Release High Memory Area (Function 02h):
  258. ----------------------------------------
  259.  
  260.     ARGS:   AH = 02h
  261.     RETS:   AX = 0001h if the HMA is successfully released, 0000h otherwise
  262.     ERRS:   BL = 80h if the function is not implemented
  263.         BL = 81h if a VDISK device is detected
  264.         BL = 90h if the HMA does not exist
  265.         BL = 93h if the HMA was not allocated
  266.  
  267.     This function releases the high memory area and allows other programs to
  268. use it.  Programs which allocate the HMA must release it before exiting.  
  269. When the HMA has been released, any code or data stored in it becomes invalid
  270. and should not be accessed.
  271.  
  272.  
  273. Global Enable A20 (Function 03h):
  274. ---------------------------------
  275.  
  276.     ARGS:   AH = 03h
  277.     RETS:   AX = 0001h if the A20 line is enabled, 0000h otherwise
  278.     ERRS:   BL = 80h if the function is not implemented
  279.         BL = 81h if a VDISK device is detected
  280.         BL = 82h if an A20 error occurs
  281.  
  282.     This function attempts to enable the A20 line.  It should only be used
  283. by programs which have control of the HMA.  The A20 line should be turned
  284. off via Function 04h (Global Disable A20) before a program releases control
  285. of the system.
  286.  
  287.     NOTE: On many machines, toggling the A20 line is a relatively slow
  288.           operation.
  289.  
  290.  
  291. Global Disable A20 (Function 04h):
  292. ----------------------------------
  293.  
  294.     ARGS:   AH = 04h
  295.     RETS:   AX = 0001h if the A20 line is disabled, 0000h otherwise
  296.     ERRS:   BL = 80h if the function is not implemented
  297.         BL = 81h if a VDISK device is detected
  298.         BL = 82h if an A20 error occurs
  299.         BL = 94h if the A20 line is still enabled
  300.     
  301.     This function attempts to disable the A20 line.  It should only be used
  302. by programs which have control of the HMA.  The A20 line should be disabled
  303. before a program releases control of the system.
  304.  
  305.     NOTE: On many machines, toggling the A20 line is a relatively slow
  306.           operation.
  307.  
  308.  
  309. Local Enable A20 (Function 05h):
  310. --------------------------------
  311.  
  312.     ARGS:   AH = 05h
  313.     RETS:   AX = 0001h if the A20 line is enabled, 0000h otherwise
  314.     ERRS:   BL = 80h if the function is not implemented
  315.         BL = 81h if a VDISK device is detected
  316.         BL = 82h if an A20 error occurs
  317.  
  318.     This function attempts to enable the A20 line.  It should only be used
  319. by programs which need direct access to extended memory.  Programs which use
  320. this function should call Function 06h (Local Disable A20) before releasing
  321. control of the system.
  322.  
  323.     NOTE: On many machines, toggling the A20 line is a relatively slow
  324.           operation.
  325.  
  326.  
  327. Local Disable A20 (Function 06h):
  328. ---------------------------------
  329.  
  330.     ARGS:   AH = 06h
  331.     RETS:   AX = 0001h if the function succeeds, 0000h otherwise
  332.     ERRS:   BL = 80h if the function is not implemented
  333.         BL = 81h if a VDISK device is detected
  334.         BL = 82h if an A20 error occurs
  335.         BL = 94h if the A20 line is still enabled
  336.  
  337.     This function cancels a previous call to Function 05h (Local Enable
  338. A20).  It should only be used by programs which need direct access to
  339. extended memory.  Previous calls to Function 05h must be canceled before
  340. releasing control of the system.
  341.  
  342.     NOTE: On many machines, toggling the A20 line is a relatively slow
  343.           operation.
  344.  
  345.  
  346. Query A20 (Function 07h):
  347. -------------------------
  348.  
  349.     ARGS:   AH = 07h
  350.     RETS:   AX = 0001h if the A20 line is physically enabled, 0000h otherwise
  351.     ERRS:   BL = 00h if the function succeeds
  352.         BL = 80h if the function is not implemented
  353.         BL = 81h if a VDISK device is detected
  354.  
  355.     This function checks to see if the A20 line is physically enabled.  It
  356. does this in a hardware independent manner by seeing if "memory wrap" occurs.
  357.  
  358.  
  359. Query Free Extended Memory (Function 08h):
  360. ------------------------------------------
  361.  
  362.     ARGS:   AH = 08h
  363.     RETS:   AX = Size of the largest free extended memory block in K-bytes
  364.         DX = Total amount of free extended memory in K-bytes
  365.     ERRS:   BL = 80h if the function is not implemented
  366.         BL = 81h if a VDISK device is detected
  367.         BL = A0h if all extended memory is allocated
  368.  
  369.     This function returns the size of the largest available extended memory
  370. block in the system.
  371.  
  372.     NOTE: The 64K HMA is not included in the returned value even if it is
  373.       not in use.
  374.  
  375.  
  376. Allocate Extended Memory Block (Function 09h):
  377. ----------------------------------------------
  378.  
  379.     ARGS:   AH = 09h
  380.             DX = Amount of extended memory being requested in K-bytes
  381.     RETS:   AX = 0001h if the block is allocated, 0000h otherwise
  382.             DX = 16-bit handle to the allocated block
  383.     ERRS:   BL = 80h if the function is not implemented
  384.         BL = 81h if a VDISK device is detected
  385.         BL = A0h if all available extended memory is allocated
  386.         BL = A1h if all available extended memory handles are in use
  387.             
  388.     This function attempts to allocate a block of the given size out of the
  389. pool of free extended memory.  If a block is available, it is reserved
  390. for the caller and a 16-bit handle to that block is returned.  The handle
  391. should be used in all subsequent extended memory calls.  If no memory was
  392. allocated, the returned handle is null.
  393.  
  394.     NOTE: Extended memory handles are scarce resources.  Programs should
  395.       try to allocate as few as possible at any one time.  When all
  396.       of a driver's handles are in use, any free extended memory is
  397.       unavailable.
  398.  
  399.  
  400. Free Extended Memory Block (Function 0Ah):
  401. ------------------------------------------
  402.  
  403.     ARGS:   AH = 0Ah
  404.             DX = Handle to the allocated block which should be freed
  405.     RETS:   AX = 0001h if the block is successfully freed, 0000h otherwise
  406.     ERRS:   BL = 80h if the function is not implemented
  407.         BL = 81h if a VDISK device is detected
  408.         BL = A2h if the handle is invalid
  409.         BL = ABh if the handle is locked
  410.  
  411.     This function frees a block of extended memory which was previously
  412. allocated using Function 09h (Allocate Extended Memory Block).  Programs
  413. which allocate extended memory should free their memory blocks before
  414. exiting.  When an extended memory buffer is freed, its handle and all data
  415. stored in it become invalid and should not be accessed.
  416.  
  417.  
  418. Move Extended Memory Block (Function 0Bh):
  419. ------------------------------------------
  420.  
  421.     ARGS:   AH = 0Bh
  422.             DS:SI = Pointer to an Extended Memory Move Structure (see below)
  423.     RETS:   AX = 0001h if the move is successful, 0000h otherwise
  424.     ERRS:   BL = 80h if the function is not implemented
  425.         BL = 81h if a VDISK device is detected
  426.         BL = 82h if an A20 error occurs
  427.         BL = A3h if the SourceHandle is invalid
  428.         BL = A4h if the SourceOffset is invalid
  429.         BL = A5h if the DestHandle is invalid
  430.         BL = A6h if the DestOffset is invalid
  431.         BL = A7h if the Length is invalid
  432.         BL = A8h if the move has an invalid overlap
  433.         BL = A9h if a parity error occurs
  434.  
  435.     Extended Memory Move Structure Definition:
  436.  
  437.         ExtMemMoveStruct    struc
  438.             Length              dd  ?   ; 32-bit number of bytes to transfer
  439.             SourceHandle        dw  ?   ; Handle of source block
  440.             SourceOffset        dd  ?   ; 32-bit offset into source 
  441.             DestHandle          dw  ?   ; Handle of destination block
  442.             DestOffset          dd  ?   ; 32-bit offset into destination block
  443.         ExtMemMoveStruct    ends
  444.             
  445.     This function attempts to transfer a block of data from one location to
  446. another.  It is primarily intended for moving blocks of data between
  447. conventional memory and extended memory, however it can be used for moving
  448. blocks within conventional memory and within extended memory.
  449.  
  450.     NOTE: If SourceHandle is set to 0000h, the SourceOffset is interpreted
  451.           as a standard segment:offset pair which refers to memory that is
  452.           directly accessible by the processor.  The segment:offset pair
  453.           is stored in Intel DWORD notation.  The same is true for DestHandle
  454.           and DestOffset.
  455.           
  456.       SourceHandle and DestHandle do not have to refer to locked memory
  457.       blocks.
  458.           
  459.       Length must be even.    Although not required, WORD-aligned moves
  460.       can be significantly faster on most machines.  DWORD aligned move
  461.       can be even faster on 80386 machines.
  462.           
  463.       If the source and destination blocks overlap, only forward moves
  464.       (i.e. where the source base is less than the destination base) are
  465.       guaranteed to work properly.
  466.           
  467.       Programs should not enable the A20 line before calling this
  468.       function.  The state of the A20 line is preserved.
  469.  
  470.       This function is guaranteed to provide a reasonable number of
  471.       interrupt windows during long transfers.
  472.           
  473.           
  474. Lock Extended Memory Block (Function 0Ch):
  475. ------------------------------------------
  476.  
  477.     ARGS:   AH = 0Ch
  478.             DX = Extended memory block handle to lock
  479.     RETS:   AX = 0001h if the block is locked, 0000h otherwise
  480.         DX:BX = 32-bit linear address of the locked block
  481.     ERRS:   BL = 80h if the function is not implemented
  482.         BL = 81h if a VDISK device is detected
  483.         BL = A2h if the handle is invalid
  484.         BL = ACh if the block's lock count overflows
  485.         BL = ADh if the lock fails
  486.             
  487.     This function locks an extended memory block and returns its base 
  488. address as a 32-bit linear address.  Locked memory blocks are guaranteed not
  489. to move.  The 32-bit pointer is only valid while the block is locked.
  490. Locked blocks should be unlocked as soon as possible.
  491.  
  492.     NOTE: A block does not have to be locked before using Function 0Bh (Move
  493.           Extended Memory Block).
  494.           
  495.       "Lock counts" are maintained for EMBs.
  496.  
  497.  
  498. Unlock Extended Memory Block (Function 0Dh):
  499. --------------------------------------------
  500.  
  501.     ARGS:   AH = 0Dh
  502.             DX = Extended memory block handle to unlock
  503.     RETS:   AX = 0001h if the block is unlocked, 0000h otherwise
  504.     ERRS:   BL = 80h if the function is not implemented
  505.         BL = 81h if a VDISK device is detected
  506.         BL = A2h if the handle is invalid
  507.         BL = AAh if the block is not locked
  508.     
  509.     This function unlocks a locked extended memory block.  Any 32-bit
  510. pointers into the block become invalid and should no longer be used.
  511.  
  512.  
  513. Get EMB Handle Information (Function 0Eh):
  514. ------------------------------------------
  515.  
  516.     ARGS:   AH = 0Eh
  517.         DX = Extended memory block handle
  518.     RETS:   AX = 0001h if the block's information is found, 0000h otherwise
  519.         BH = The block's lock count
  520.         BL = Number of free EMB handles in the system
  521.         DX = The block's length in K-bytes
  522.     ERRS:   BL = 80h if the function is not implemented
  523.         BL = 81h if a VDISK device is detected
  524.         BL = A2h if the handle is invalid
  525.  
  526.     This function returns additional information about an extended memory
  527. block to the caller.
  528.  
  529.     NOTE: To get the block's base address, use Function 0Ch (Lock Extended
  530.       Memory Block).
  531.           
  532.           
  533. Reallocate Extended Memory Block (Function 0Fh):
  534. ------------------------------------------------
  535.  
  536.     ARGS:   AH = 0Fh
  537.         BX = New size for the extended memory block in K-bytes
  538.         DX = Unlocked extended memory block handle to reallocate
  539.     RETS:   AX = 0001h if the block is reallocated, 0000h otherwise
  540.     ERRS:   BL = 80h if the function is not implemented
  541.         BL = 81h if a VDISK device is detected
  542.         BL = A0h if all available extended memory is allocated
  543.         BL = A1h if all available extended memory handles are in use
  544.         BL = A2h if the handle is invalid
  545.         BL = ABh if the block is locked
  546.  
  547.     This function attempts to reallocate an unlocked extended memory block
  548. so that it becomes the newly specified size.  If the new size is smaller
  549. than the old block's size, all data at the upper end of the old block is
  550. lost.
  551.  
  552.  
  553. Request Upper Memory Block (Function 10h):
  554. ------------------------------------------
  555.  
  556.     ARGS:   AH = 10h
  557.         DX = Size of requested memory block in paragraphs
  558.     RETS:   AX = 0001h if the request is granted, 0000h otherwise
  559.         BX = Segment number of the upper memory block
  560.             If the request is granted,
  561.         DX = Actual size of the allocated block in paragraphs
  562.         otherwise,
  563.         DX = Size of the largest available UMB in paragraphs
  564.     ERRS:   BL = 80h if the function is not implemented
  565.         BL = B0h if a smaller UMB is available
  566.         BL = B1h if no UMBs are available
  567.  
  568.     This function attempts to allocate an upper memory block to the caller.
  569. If the function fails, the size of the largest free UMB is returned in DX.
  570.  
  571.     NOTE: By definition UMBs are located below the 1MB address boundary.
  572.       The A20 Line does not need to be enabled before accessing an
  573.       allocated UMB.
  574.  
  575.       UMBs are paragraph aligned.
  576.  
  577.       To determine the size of the largest available UMB, attempt to
  578.       allocate one with a size of FFFFh.
  579.  
  580.       UMBs are unaffected by EMS calls.
  581.  
  582.  
  583. Release Upper Memory Block (Function 11h):
  584. ------------------------------------------
  585.  
  586.     ARGS:   AH = 11h
  587.         DX = Segment number of the upper memory block
  588.     RETS:   AX = 0001h if the block was released, 0000h otherwise
  589.     ERRS:   BL = 80h if the function is not implemented
  590.         BL = B2h if the UMB segment number is invalid
  591.  
  592.     This function frees a previously allocated upper memory block.  When an
  593. UMB has been released, any code or data stored in it becomes invalid and
  594. should not be accessed.
  595.  
  596.  
  597. PRIORITIZING HMA USAGE:
  598. -----------------------
  599.  
  600.     For DOS users to receive the maximum benefit from the High Memory Area,
  601. programs which use the HMA must store as much of their resident code in it as
  602. is possible.  It is very important that developers realize that the HMA is
  603. allocated as a single unit. 
  604.  
  605.     For example, a TSR program which grabs the HMA and puts 10K of code into
  606. it may prevent a later TSR from putting 62K into the HMA.  Obviously, regular
  607. DOS programs would have more memory available to them below the 640K line if
  608. the 62K TSR was moved into the HMA instead of the 10K one.
  609.  
  610.     The first method for dealing with conflicts such as this is to require 
  611. programs which use the HMA to provide a command line option for disabling
  612. this feature.  It is crucial that TSRs which do not make full use of the HMA
  613. provide such a switch on their own command line (suggested name "/NOHMA").
  614.  
  615.     The second method for optimizing HMA usage is through the /HMAMIN=
  616. parameter on the XMS device driver line.  The number after the parameter
  617. is defined to be the minimum amount of HMA space (in K-bytes) used by any
  618. driver or TSR.    For example, if "DEVICE=HIMEM.SYS /HMAMIN=48" is in a
  619. user's CONFIG.SYS file, only programs which request at least 48K would be
  620. allowed to allocate the HMA.  This number can be adjusted either by
  621. installation programs or by the user himself.  If this parameter is not
  622. specified, the default value of 0 is used causing the HMA to be allocated
  623. on a first come, first served basis.
  624.  
  625.     Note that this problem does not impact application programs.  If the HMA
  626. is available when an application program starts, the application is free to
  627. use as much or as little of the HMA as it wants.  For this reason,
  628. applications should pass FFFFh in DX when calling Function 01h.
  629.  
  630.  
  631. HIGH MEMORY AREA RESTRICTIONS:
  632. ------------------------------
  633.  
  634. -   Far pointers to data located in the HMA cannot be passed to DOS.  DOS
  635.     normalizes any pointer which is passed into it.  This will cause data
  636.     addresses in the HMA to be invalidated.
  637.  
  638. -   Disk I/O directly into the HMA (via DOS, INT 13h, or otherwise) is not
  639.     recommended.
  640.        
  641. -   Programs, especially drivers and TSRs, which use the HMA *MUST* use
  642.     as much of it as possible.  If a driver or TSR is unable to use at
  643.     least 90% of the available HMA (typically ~58K), they must provide
  644.     a command line switch for overriding HMA usage.  This will allow
  645.     the user to configure his machine for optimum use of the HMA.
  646.        
  647. -   Device drivers and TSRs cannot leave the A20 line permanently turned
  648.     on.  Several applications rely on 1MB memory wrap and will overwrite the
  649.     HMA if the A20 line is left enabled potentially causing a system crash.
  650.         
  651. -   Interrupt vectors must not point into the HMA.  This is a result of
  652.     the previous restriction.  Note that interrupt vectors can point into
  653.     any allocated upper memory blocks however.
  654.  
  655. ERROR CODE INDEX:
  656. -----------------
  657.  
  658. If AX=0000h when a function returns and the high bit of BL is set,
  659.  
  660.     BL=80h if the function is not implemented
  661.        81h if a VDISK device is detected
  662.        82h if an A20 error occurs
  663.        8Eh if a general driver error occurs
  664.        8Fh if an unrecoverable driver error occurs
  665.        90h if the HMA does not exist
  666.        91h if the HMA is already in use
  667.        92h if DX is less than the /HMAMIN= parameter
  668.        93h if the HMA is not allocated
  669.        94h if the A20 line is still enabled
  670.        A0h if all extended memory is allocated
  671.        A1h if all available extended memory handles are in use
  672.        A2h if the handle is invalid
  673.        A3h if the SourceHandle is invalid
  674.        A4h if the SourceOffset is invalid
  675.        A5h if the DestHandle is invalid
  676.        A6h if the DestOffset is invalid
  677.        A7h if the Length is invalid
  678.        A8h if the move has an invalid overlap
  679.        A9h if a parity error occurs
  680.        AAh if the block is not locked
  681.        ABh if the block is locked
  682.        ACh if the block's lock count overflows
  683.        ADh if the lock fails
  684.        B0h if a smaller UMB is available
  685.        B1h if no UMBs are available
  686.        B2h if the UMB segment number is invalid
  687.  
  688. IMPLEMENTATION NOTES FOR DOS XMS DRIVERS:
  689. -----------------------------------------
  690.  
  691. -   A DOS XMS driver's control function must begin with code similar to the
  692.     following:
  693.  
  694. XMMControl  proc    far
  695.  
  696.         jmp     short XCControlEntry    ; For "hookability"
  697.         nop                 ; NOTE: The jump must be a short
  698.         nop                 ;  jump to indicate the end of
  699.         nop                 ;  any hook chain.    The nop's
  700.                         ;  allow a far jump to be
  701.                         ;  patched in.
  702. XCControlEntry:
  703.  
  704.  
  705. -   XMS drivers must preserve all registers except those containing
  706.     returned values across any function call.
  707.  
  708. -   XMS drivers are required to hook INT 15h and watch for calls to
  709.     functions 87h (Block Move) and 88h (Extended Memory Available).  The
  710.     INT 15h Block Move function must be hooked so that the state of the A20
  711.     line is preserved across the call.    The INT 15h Extended Memory
  712.     Available function must be hooked to return 0h to protect the HMA.
  713.  
  714. -   In order to maintain compatibility with existing device drivers, DOS XMS
  715.     drivers must not hook INT 15h until the first non-Version Number call
  716.     to the control function is made.
  717.  
  718. -   XMS drivers are required to check for the presence of drivers which
  719.     use the IBM VDISK allocation scheme.  Note that it is not sufficient to
  720.     check for VDISK users at installation time but at the time when the HMA
  721.     is first allocated.  If a VDISK user is detected, the HMA must not be
  722.     allocated.    Microsoft will publish a standard method for detecting
  723.     drivers which use the VDISK allocation scheme.
  724.  
  725. -   XMS drivers which have a fixed number of extended memory handles (most
  726.     do) should implement a command line parameter for adjusting that number
  727.     (suggested name "/NUMHANDLES=")
  728.  
  729. -   XMS drivers should make sure that the major DOS version number is
  730.     greater than or equal to 3 before installing themselves.
  731.  
  732. -   UMBs cannot occupy memory addresses that can be banked by EMS 4.0.
  733.     EMS 4.0 takes precedence over UMBs for physically addressable memory.
  734.  
  735. -   All driver functions must be re-entrant.  Care should be taken to not
  736.     leave interrupts disabled for long periods of time.
  737.  
  738. -   Allocation of a zero length extended memory buffer is allowed.  Programs
  739.     which hook XMS drivers may need to reserve a handle for private use via
  740.     this method.  Programs which hook an XMS driver should pass all requests
  741.     for zero length EMBs to the next driver in the chain.
  742.  
  743. -   Drivers should control the A20 line via an "enable count."    Local En-
  744.     able only enables the A20 line if the count is zero.  It then increments
  745.     the count.    Local Disable only disables A20 if the count is one.  It
  746.     then decrements the count.    Global Enable/Disable keeps a flag which
  747.     indicates the state of A20.  They use Local Enable/Disable to actually
  748.     change the state.
  749.  
  750. IMPLEMENTATION NOTES FOR HIMEM.SYS:
  751. -----------------------------------
  752.  
  753. -   HIMEM.SYS currently supports true AT-compatibles, 386 AT machines, IBM
  754.     PS/2s, AT&T 6300 Plus systems and Hewlett Packard Vectras.
  755.  
  756. -   If HIMEM finds that it cannot properly control the A20 line or if there
  757.     is no extended memory available when HIMEM.SYS is invoked, the driver
  758.     does not install itself.  HIMEM.SYS displays the message "High Memory
  759.     Area Unavailable" when this situation occurs.
  760.  
  761. -   If HIMEM finds that the A20 line is already enabled when it is invoked,
  762.     it will NOT change the A20 line's state.  The assumption is that whoever
  763.     enabled it knew what they were doing.  HIMEM.SYS displays the message "A20
  764.     Line Permanently Enabled" when this situation occurs.
  765.  
  766. -   HIMEM.SYS is incompatible with IBM's VDISK.SYS driver and other drivers
  767.     which use the VDISK scheme for allocating extended memory.  However, 
  768.     HIMEM does attempt to detect these drivers and will not allocate the
  769.     HMA if one is found.
  770.  
  771. -   HIMEM.SYS supports the optional "/HMAMIN=" parameter.  The valid values
  772.     are decimal numbers between 0 and 63.
  773.  
  774. -   By default, HIMEM.SYS has 32 extended memory handles available for use.
  775.     This number may be adjusted with the "/NUMHANDLES=" parameter.  The
  776.     maximum value for this parameter is 128 and the minimum is 0.  Each
  777.     handle currently requires 6 bytes of resident space.
  778.  
  779.  
  780. Copyright (c) 1988, Microsoft Corporation
  781.